﻿<link href="~/lib/ztree/ztree.css" rel="stylesheet" asp-append-version="true" />
<script src="~/lib/ztree/ztree.core-3.5.37.min.js" asp-append-version="true"></script>
<script src="~/lib/ztree/ztree.exedit-3.5.37.js" asp-append-version="true"></script>
<script type="text/javascript">
	var treeSetting = {
		view: {
			selectedMulti: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onTreeClick,
		}
	};

	function onTreeClick(event, treeId, treeNode, clickFlag) {
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.@(ViewData["callback"]) && parent.@(ViewData["callback"])(treeNode);
		parent.layer.close(index);
	}

	function treeRefresh() {
		utils.ajaxPost('@(Url.Action("GetTreeData", "Sys_Dept"))', { deptid: "@(ViewData["deptid"])",orgid:"@(ViewData["orgid"])" }, function (resp) {
			var data = resp.data || [];
			var treeData = [];
			var codes = [];
			treeData.push({
				id: '0',
				pId: "-1",
				name: "全部",
				code: "",
				isParent: true,
				open: true
			});
			$.each(data, function (item, idx) {
				var code = item.OrgID + '-' +item.PID+'-'+ item.ID;
				if (codes.indexOf(code) < 0) {
					treeData.push({
						id: code,
						pId: 0,
						orgid: item.OrgID,
						name: item.OrgName,
						code: '' + item.OrgID,
						isParent: true,
						open: true
					});
				}
				treeData.push({
					id: item.n,
					pId: "-1",
					orgid: item.OrgID,
					deptid:item.ID,
					name: "全部",
					code: "",
					isParent: true,
					open: true
				});
			});
			//$.fn.zTree.init($("#deptTree"), treeSetting, resp.data);
		});
	}

	$(document).ready(function () {
		treeRefresh();
	});
</script>